package com.mijie.homi.api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mijie.core.Status;
import com.mijie.homi.service.common.StatService;
import com.mijie.homi.util.ServerHelper;
import com.mijie.util.HttpUtil;


@Controller
@RequestMapping("/stat")
public class StatApi {

	@Autowired
	private StatService statService;
	private Logger logger = Logger.getLogger(ReportApi.class);
	
	@RequestMapping(value="/active",method=RequestMethod.GET)
	public @ResponseBody void active(HttpServletRequest request,HttpServletResponse response,
			@RequestHeader int channel,@RequestHeader String deviceId){
		int succ = statService.active(channel, deviceId);
		if(succ>0){
			//运营要求两种统计都要做
			ServerHelper.logDeviceActive(HttpUtil.getIp(request), deviceId);
		}
		new Status(request,response).write();
	}
	
	@RequestMapping(value="/signin/prepare",method=RequestMethod.GET)
	public @ResponseBody void prepareSignin(HttpServletRequest request,HttpServletResponse response,
			@RequestHeader int channel,@RequestHeader String deviceId){
		statService.prepareSignin(channel, deviceId);
		new Status(request,response).write();
	}
	
	@RequestMapping(value="/signin/finish",method=RequestMethod.GET)
	public @ResponseBody void finishSignin(HttpServletRequest request,HttpServletResponse response,
			@RequestHeader int channel,@RequestHeader String deviceId){
		statService.finishSignin(channel, deviceId);
		new Status(request,response).write();
	}
	
	@RequestMapping(value="/signup/prepare/normal",method=RequestMethod.GET)
	public @ResponseBody void prepareSignup(HttpServletRequest request,HttpServletResponse response,
			@RequestHeader int channel,@RequestHeader String deviceId){
		statService.prepareSignup(channel, deviceId);
		new Status(request,response).write();
	}
	
	@RequestMapping(value="/signup/prepare/using_sina_weibo",method=RequestMethod.GET)
	public @ResponseBody void prepareSignupUsingSinaWeibo(HttpServletRequest request,HttpServletResponse response,
			@RequestHeader int channel,@RequestHeader String deviceId){
		statService.prepareSignupUsingSinaWeibo(channel, deviceId);
		new Status(request,response).write();
	}
	
	
	@RequestMapping(value="/signup/prepare/using_qq_weibo",method=RequestMethod.GET)
	public @ResponseBody void prepareSignupUsingQQWeibo(HttpServletRequest request,HttpServletResponse response,
			@RequestHeader int channel,@RequestHeader String deviceId){
		statService.prepareSignupUsingQQWeibo(channel, deviceId);
		new Status(request,response).write();
	}
	
}
